package Controleur;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import Modele.Coordonnee;
import Modele.Partie;
import Modele.Region;
import Vue.Jeu;

public class JeuMouseListener implements MouseListener {
	private Jeu vue;
	private Partie modele;
	private static Region regionStac;
	private static String choix = "vide";

	public JeuMouseListener(Jeu fenetre, Partie partie) {
		this.vue = fenetre;
		this.modele = partie;
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {

	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		if (arg0.getX() < 913 && arg0.getY() < 763) {
			Coordonnee c = new Coordonnee(arg0.getX(), arg0.getY());
			Region region = modele.getRegionWithPos(c);
			if (region != null) {
				String[] options = { "Attaquer", "Rester", "Soutien defensif", "Soutien offensif",
						"Convoi" };
				if (regionStac != null && choix != null) {
					String[] valide = { "Valider", "Annuler" };
					int n = JOptionPane.showOptionDialog(new JFrame(), regionStac.getNom() + " "
							+ choix + " " + region.getNom() + "\n Valider", "Diplomacy",
							JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
							valide, valide[0]);
					if (n == 0) {
						JOptionPane.showMessageDialog(new JFrame("Message"), regionStac.getNom()
								+ " " + choix + " " + region.getNom());
					} else {
						JOptionPane.showMessageDialog(new JFrame("Message"), "Annulation");
					}
					regionStac = null;
					choix = null;
				} else {
					int n = JOptionPane.showOptionDialog(new JFrame(),
							"Que souhaitez-vous faire ?", "Diplomacy",
							JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
							options, options[2]);
					regionStac = region;
					choix = options[n];
				}
				System.out.println(region);
			}
		}
	}

}
